package com.canaan.business.controller.pc.storehouse;

import com.canaan.business.domain.storehouse.WmsBarcodeRecord;
import com.canaan.business.service.storehouse.IWmsBarcodeRecordService;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.core.page.TableDataInfo;
import com.canaan.common.enums.BusinessType;
import com.canaan.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 条码记录Controller
 *
 * @author ruoyi
 * @date 2022-11-30
 */
@Api(tags = "条码记录管理")
@RestController
@RequestMapping("/storehouse/barcode")
public class WmsBarcodeRecordController extends BaseController
{
    @Autowired
    private IWmsBarcodeRecordService wmsBarcodeRecordService;

    /**
     * 查询条码记录列表
     */
    @ApiOperation("查询条码记录列表")
    @GetMapping("/list")
    public TableDataInfo list(WmsBarcodeRecord wmsBarcodeRecord)
    {
        startPage();
        List<WmsBarcodeRecord> list = wmsBarcodeRecordService.selectWmsBarcodeRecordList(wmsBarcodeRecord);
        return getDataTable(list);
    }

    /**
     * 导出条码记录列表
     */
    @ApiOperation(value = "导出条码记录列表")
    @Log(title = "条码记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsBarcodeRecord wmsBarcodeRecord)
    {
        List<WmsBarcodeRecord> list = wmsBarcodeRecordService.selectWmsBarcodeRecordList(wmsBarcodeRecord);
        ExcelUtil<WmsBarcodeRecord> util = new ExcelUtil<WmsBarcodeRecord>(WmsBarcodeRecord.class);
        util.exportExcel(response, list, "条码记录数据");
    }

    /**
     * 获取条码记录详细信息
     */
    @ApiOperation(value = "获取条码记录详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wmsBarcodeRecordService.selectWmsBarcodeRecordById(id));
    }

    /**
     * 新增条码记录
     */
    @ApiOperation("新增条码记录")
    @Log(title = "条码记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated WmsBarcodeRecord wmsBarcodeRecord)
    {
        wmsBarcodeRecord.setCreateBy(getUsername());
        return success(wmsBarcodeRecordService.insertWmsBarcodeRecord(wmsBarcodeRecord));
    }

    /**
     * 修改条码记录
     */
    @ApiOperation("修改条码记录")
    @Log(title = "条码记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated WmsBarcodeRecord wmsBarcodeRecord)
    {
        return toAjax(wmsBarcodeRecordService.updateWmsBarcodeRecord(wmsBarcodeRecord));
    }

    /**
     * 删除条码记录
     */
    @ApiOperation(value = "删除条码记录")
    @Log(title = "条码记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsBarcodeRecordService.deleteWmsBarcodeRecordByIds(ids));
    }
    /**
     * 获取绑定容器绑定的条码信息
     */
    @GetMapping(value = "getBindContainBacodeInfo/{barcode}")
    @ApiOperation("获取绑定容器的条码信息")
    public AjaxResult getBindContainBacodeInfo(@PathVariable("barcode") String barcode){
        return success(wmsBarcodeRecordService.getBindContainBacodeInfo(barcode));
    }

    /**
     * 获取入库条码信息
     */
    @GetMapping(value = "getInStockBarcodeInfo/{barcode}")
    @ApiOperation("获取入库条码信息")
    public AjaxResult getInStockBarcodeInfo(@PathVariable("barcode") String barcode)
    {
        return success(wmsBarcodeRecordService.getInStockBarcodeInfo(barcode,null,1));
    }

    /**
     * 获取出库条码信息
     */
    @GetMapping(value = "getOutStockBarcodeInfo/{barcode}")
    @ApiOperation("获取出库条码信息")
    public AjaxResult getOutStockBarcodeInfo(@PathVariable("barcode") String barcode)
    {
        return success(wmsBarcodeRecordService.getOutStockBarcodeInfo(barcode));
    }

    /**
     * 获取根据条码获取条码信息
     */
    @GetMapping(value = "getInfoByBarcode/{barcode}")
    @ApiOperation("获取根据条码获取条码信息")
    public AjaxResult getInfoByBarcode(@PathVariable("barcode") String barcode) {
        return success(wmsBarcodeRecordService.selectLastBarcode(barcode));
    }
}
